<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>流程列表</title>
    <div th:include="layout/resources :: resources"></div>
</head>
<body>
<div>
    <div class="container-fluid">
        <div id="toolbar" class="btn-group">
            <button onclick="toAdd();">添加</button>
        </div>
        <table id="list"></table>
    </div>
</div>
</body>
<script th:inline="javascript">
    $(function () {
    })
    $("#list").framework().bootstrapTable({
        url: "/fun/flow/getList/[[${fun}]]",
        pagination: false,
        columns: [{
            field: '',
            title: '序号',
            align: 'center',
            valign: 'middle',
            formatter: function (value, row, index) {
                return index + 1;
            }
        }, {
            field: 'id',
            title: '操作',
            align: 'center',
            valign: 'middle',
            formatter: function (value, row, index) {
                return '<a href="javascript:deleteOne(\'' + value + '\');">删除</a>';
            }
        }, {
            field: 'describe',
            title: '流程名',
            align: 'center',
            valign: 'middle',
            formatter: function (value, row, index) {
                return '<a href="javascript:addAction(' + row.id + ');">' + value + '</a>';
            }
        }],
        responseHandler: function (res) {
            return {rows: res}
        }
    });

    function refresh() {
        $('#list').bootstrapTable('refresh');
    }

    function toAdd() {
        framework.openWindow("/fun/flow/toAdd/[[${fun}]]", "50%", "50%", "添加流程");
    }

    function addAction(flowId) {
        framework.openWindow("/fun/action/toAdd/[[${fun}]]/" + flowId, "90%", "90%", "添加动作", "no");
    }
    function deleteOne(id) {
        layer.confirm('确认删除吗？', {
            btn: ['确认', '取消'] //按钮
        }, function () {
            $.ajax({
                method: "get",
                url: createUrl('/fun/flow/delete?id=' + id + "&fun=" + "${fun}"),
                success: function (result) {
                    if (result.success) {
                        refresh();
                        framework.alert("删除成功");
                    } else {
                        framework.alert("删除失敗:" + result.error);
                    }
                    layer.close(index);
                }
            })
        }, function () {
            layer.closeAll();
        });
    }
</script>
</html>
